import {
  RoleCreateDto,
  RoleFindDto,
  RoleQueryDto,
  RoleRemoveDto,
  RoleUpdateDto,
} from '@/dtos';
import { RoleService } from '@/services/role.service';
import { ok } from '@/utils';
import { Body, Controller, Delete, Patch, Post, Query } from '@nestjs/common';
import { BaseController } from './base.controller';

@Controller('role')
export class RoleController extends BaseController {
  constructor(private readonly roleService: RoleService) {
    super();
  }

  @Post('admin/query')
  async query(@Body() dto: RoleQueryDto) {
    return ok(await this.roleService.query(dto));
  }

  @Post('admin/find')
  async find(@Body() dto: RoleFindDto) {
    return ok(await this.roleService.findOne(dto.where, dto.select));
  }

  @Post('admin/create')
  async create(@Body() dto: RoleCreateDto) {
    return ok(await this.roleService.create(dto.data));
  }

  @Patch('admin/update')
  async update(@Body() dto: RoleUpdateDto) {
    return ok(await this.roleService.update(dto));
  }

  @Delete('admin/remove')
  async remove(@Query() dto: RoleRemoveDto) {
    return ok(await this.roleService.remove(dto));
  }
}
